#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
企业微信配置类
"""

import os
from typing import Optional

class WXConfig:
    """企业微信配置管理类"""
    
    def __init__(self, config_file: Optional[str] = None):
        """
        初始化配置
        
        Args:
            config_file: 配置文件路径（可选）
        """
        self.config_file = config_file
        self._token = None
        self._encoding_aes_key = None
        self._receive_id = None
        self._debug = False
    
    def get_token(self) -> Optional[str]:
        """获取Token"""
        if self._token:
            return self._token
        return os.getenv('WX_TOKEN')
    
    def get_encoding_aes_key(self) -> Optional[str]:
        """获取EncodingAESKey"""
        if self._encoding_aes_key:
            return self._encoding_aes_key
        return os.getenv('WX_AES_KEY')
    
    def get_receive_id(self) -> Optional[str]:
        """获取ReceiveId"""
        if self._receive_id:
            return self._receive_id
        return os.getenv('WX_RECEIVE_ID')
    
    def is_debug(self) -> bool:
        """是否开启调试模式"""
        return self._debug or os.getenv('DEBUG', 'false').lower() == 'true'
    
    def set_token(self, token: str):
        """设置Token"""
        self._token = token
    
    def set_encoding_aes_key(self, encoding_aes_key: str):
        """设置EncodingAESKey"""
        self._encoding_aes_key = encoding_aes_key
    
    def set_receive_id(self, receive_id: str):
        """设置ReceiveId"""
        self._receive_id = receive_id
    
    def set_debug(self, debug: bool):
        """设置调试模式"""
        self._debug = debug

class WXUtils:
    """企业微信工具类"""
    
    @staticmethod
    def validate_config(token: Optional[str], encoding_aes_key: Optional[str], receive_id: Optional[str]) -> bool:
        """
        验证配置参数
        
        Args:
            token: Token
            encoding_aes_key: EncodingAESKey
            receive_id: ReceiveId
            
        Returns:
            bool: 配置是否有效
        """
        if not token:
            print("警告: Token未配置")
            return False
        
        if not encoding_aes_key:
            print("警告: EncodingAESKey未配置")
            return False
        
        if not receive_id:
            print("警告: ReceiveId未配置")
            return False
        
        # 验证EncodingAESKey长度（应该是43位）
        if len(encoding_aes_key) != 43:
            print("警告: EncodingAESKey长度应为43位")
            return False
        
        return True 